﻿using Microsoft.AspNetCore.Mvc;
using MVC.Models;
using MVC.Models.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MVC.Controllers
{
    public class AddUController : Controller
    {
        private readonly LifengContext _context;
        public AddUController(LifengContext context)
        {
            _context = context;
        }

        [Route("/AddU")]
        public IActionResult AddU()
        {
            return View();
        }

        [HttpPost]
        [Route("/api/AddUser")]
        //添加
        public IActionResult AddUser(AddUser request)
        {
            Random random = new Random();
            var userid = request.UserId;
            var username = request.UserName;
            var userpassword = request.UserPassword;
            var useremail = request.UserEmail;
            _context.Add(new User
            {
                UserId = userid,
                UserName = username,
                UserPassword = userpassword,
                UserEmail = useremail
            });
            _context.SaveChanges();
            return Json(new { code = 200, msg = "添加成功" });
        }
    }
}
